package cn.accp.kzy.util;

import java.io.*;
import java.util.UUID;

public class CommonUtils {

	 public static String reName(String fileName) {
		 String newFileName = null;
		 int index = fileName.lastIndexOf('.');
		 if (index != -1) {
		 newFileName = UUID.randomUUID().toString() + fileName.substring(index);
		 } else
		 newFileName = UUID.randomUUID().toString();

		 return newFileName;
		 }

	
	public static void copyFile(File source, File destination) throws Exception {
		try {
			InputStream in = null;
			OutputStream out = null;
			try {
				in = new BufferedInputStream(new FileInputStream(source),
						2048);
				out = new BufferedOutputStream(
						new FileOutputStream(destination), 2048);
				byte[] buf = new byte[2048];
				while (in.read(buf) > 0) {
					out.write(buf);
				}
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			} catch (IOException e) {
				e.printStackTrace();
			} finally {
				if (in != null)
					in.close();
				if (out != null)
					out.close();
			}
		} catch (Exception e) {
			e.printStackTrace();
			throw new Exception(e);
		}

	}
}
